package cn.apthink.calendar;

import java.util.List;
import java.util.Optional;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DepartmentHelper {
	private List<Department> lstDepartment;
	
	public String getPid(String departmentId) {
		Department d = get(departmentId);
		return d.getPid();
	}
	public Department getParent(String departmentId) {
		String pid = getPid(departmentId);
		return get(pid);
	}
	
	public Department get(String departmentId) {
		Optional<Department> o = lstDepartment.stream().filter(x -> {
			return x.getId().equals(departmentId);
		}).findAny();
		if (!o.isPresent()) {
			throw new RuntimeException("单位id不存在");
		} else {
			return o.get();
		}					
	}
}
